package com.bjb.vr.manager.controller;

import com.bjb.vr.common.ao.ResDeviceAo;
import com.bjb.vr.common.ao.ResDeviceContentAo;
import com.bjb.vr.common.result.BaseErrorCode;
import com.bjb.vr.common.result.BaseResult;
import com.bjb.vr.common.result.CommonResult;
import com.bjb.vr.common.service.ResGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 分组和设备
 *
 * @author maxingchen
 * @version 1.0
 * @date 2022/4/13 2:40 下午
 */
@RestController
@RequestMapping("/api/manager/v1")
public class DeviceController {

    @Autowired
    ResGroupService groupService;

    /**
     * 查询一共有多少个设备组res_group ，每个设备组有多少台设备 res_group_ref
     *
     * @param authorization
     * @return
     */
    @PostMapping("/queryGroupNumbers")
    public BaseResult queryGroupNumbers(@RequestHeader String authorization) {
        return CommonResult.Ok().setResult(groupService.queryGroupNumbers(authorization));
    }

    /**
     * 按设备组查询设备列表res_group_ref 关联  res_device
     *
     * @param resDeviceAo
     * @param authorization
     * @return
     */
    @PostMapping("/queryOneGroupNumbers")
    public BaseResult queryOneGroupNumbers(@RequestBody ResDeviceAo resDeviceAo, @RequestHeader String authorization) {
        return CommonResult.Ok().setResult(groupService.queryOneGroupNumbers(resDeviceAo, authorization));
    }


    /**
     * 设备管理中，查询一共有多少个设备组 ，每个设备组有多少台设备，以及设备总数
     * @return
     */
    @PostMapping("/queryDeviceAndGroup")
    public BaseResult queryDeviceAndGroup() {
        return CommonResult.Ok().setResult(groupService.queryDeviceAndGroup());
    }

    /**
     * 设备管理全部和每组设备接口
     *
     * @param authorization
     * @return
     */
    @PostMapping("/queryDeviceInfoAndGroup")
    public BaseResult queryDeviceInfoAndGroup(@RequestBody ResDeviceAo resDeviceAo, @RequestHeader String authorization) {
        return CommonResult.Ok().setResult(groupService.queryDeviceInfoAndGroup(resDeviceAo, authorization));
    }

    /**
     * 根据设备id查询课程资源列表接口
     *
     * @param resDeviceContentAo
     * @return
     */
    @PostMapping("/selectContentByDeviceId")
    public BaseResult selectContentByDeviceId(@RequestBody ResDeviceContentAo resDeviceContentAo) {
        return CommonResult.Ok().setResult(groupService.selectContentByDeviceId(resDeviceContentAo));
    }

    /**
     * 根据设备id批量删除已安装资源接口
     *
     * @param resDeviceContentAo
     * @return
     */
    @PostMapping("/deleteContentByDeviceId")
    public BaseResult deleteContentByDeviceId(@RequestBody ResDeviceContentAo resDeviceContentAo) {
        int statu = groupService.deleteContentByDeviceId(resDeviceContentAo);
        if (statu > 0) {
            return CommonResult.Ok();
        } else {
            return CommonResult.Fail(BaseErrorCode.ERROR_REMOVE);
        }
    }

    /**
     * 根据课程查询一共几个组，每个组分别有哪些设备详情；
     *
     * @param resDeviceContentAo
     * @return
     */
    @PostMapping("/selectDeviceAllByContentId")
    public BaseResult selectDeviceAllByContentId(@RequestBody ResDeviceContentAo resDeviceContentAo) {
        return CommonResult.Ok().setResult(groupService.selectDeviceAllByContentId(resDeviceContentAo));
    }

}
